<template>
  <div class="skeleton-container">
    <!-- 商品卡片骨架屏 -->
    <div class="skeleton-card" v-if="type === 'product'">
      <div class="skeleton-image"></div>
      <div class="skeleton-title"></div>
      <div class="skeleton-price"></div>
    </div>
    
    <!-- 列表骨架屏 -->
    <div class="skeleton-list" v-if="type === 'list'">
      <div v-for="i in count" :key="i" class="skeleton-item">
        <div class="skeleton-image"></div>
        <div class="skeleton-content">
          <div class="skeleton-line"></div>
          <div class="skeleton-line"></div>
          <div class="skeleton-line short"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
defineProps({
  type: {
    type: String,
    default: 'product', // 'product' | 'list'
    validator: (value: string) => ['product', 'list'].includes(value)
  },
  count: {
    type: Number,
    default: 5
  }
})
</script>

<style scoped>
.skeleton-container {
  width: 100%;
}

.skeleton-card {
  width: 100%;
  padding: 16px;
}

.skeleton-image {
  width: 100%;
  height: 200px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
  margin-bottom: 12px;
}

.skeleton-title {
  width: 80%;
  height: 20px;
  background: #f0f0f0;
  border-radius: 4px;
  margin-bottom: 8px;
  animation: shimmer 1.5s infinite;
}

.skeleton-price {
  width: 40%;
  height: 16px;
  background: #f0f0f0;
  border-radius: 4px;
  animation: shimmer 1.5s infinite;
}

.skeleton-list {
  padding: 16px;
}

.skeleton-item {
  display: flex;
  margin-bottom: 16px;
  gap: 12px;
}

.skeleton-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-line {
  height: 16px;
  background: #f0f0f0;
  border-radius: 4px;
  animation: shimmer 1.5s infinite;
}

.skeleton-line.short {
  width: 60%;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}
</style>